//在数组中查找元素值  
// 返回-1表示没找到，返回其他值表示找到的索 
function in_array(v, a) {  
  var i;  
  for (i = 0; i < a.length; i++) {  
	if (v === a[i]) {  
	  return i;  
	}  
  }  
  return -1;  
} 


//四舍五入
Number.prototype.toFixed=function(num) 
{ 
   with(Math)this.NO=round(this.valueOf()*pow(10,num))/pow(10,num); 
   return String(/\./g.exec(this.NO)?this.NO:this.NO+"."+String(Math.pow(10,num)).substr(1,num)); 
} 

function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		if (d1 == 10) {
			numString = numString.substring(0, numString.lastIndexOf("."));
			var roundedNum = Number(numString) + 1;
			newString = roundedNum.toString() + '.';
		} else {
			newString = numString.substring(0,cutoff) + d1.toString();
		}
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	//var newNumber = Number(newString);// make it a number if you like
	return newString; // Output the result to the form field (change for your purposes)
}


//周几
function getDay(date) {
	var weekday=new Array(7);
	weekday[0]="周日";
	weekday[1]="周一";
	weekday[2]="周二";
	weekday[3]="周三";
	weekday[4]="周四";
	weekday[5]="周五";
	weekday[6]="周六";
	return weekday[date.getDay()];
}

function getDay2(date) {
	if(date == "Mon") 
		return "周一";
	else if(date == "Tue") 
		return "周二";
	else if(date == "Wed") 
		return "周三";
	else if(date == "Thu") 
		return "周四";
	else if(date == "Fri") 
		return "周五";
	else if(date == "Sat") 
		return "周六";
	else if(date == "Sun") 
		return "周日";
}

//数字加逗号
function addCommas(nStr)
{
 nStr += '';
 x = nStr.split('.');
 x1 = x[0];
 x2 = x.length > 1 ? '.' + x[1] : '';
 var rgx = /(\d+)(\d{3})/;
 while (rgx.test(x1)) {
  x1 = x1.replace(rgx, '$1' + ',' + '$2');
 }
 return x1 + x2;
}

//切换图表类型
function changeChartType(category, type, typeValue) {	
	if($("#"+category+type+"Tab").hasClass("selbitem") == false) {
		$(".citem").removeClass("selbitem");
		$("#"+category+type+"Tab").addClass("selbitem");
		if(type == "All")
			$("."+category+"Chart").show("blind", {}, 500);	
		else {
			$("."+category+"Chart").hide();
			$("#"+category+type).show("blind", {}, 500);
			$("#"+category+"Area").hide();
			if(type == "Pie")
				$("#"+category+"Area").show("blind", {}, 500);
		}
	}
    
    $("#createcsv").click();

}

// 表格鼠标移动行变色
function tr_hover(obj, hover_css)
{
  obj.mouseover(function() {
	$(this).addClass(hover_css);
  });
  obj.mouseout(function() {
	$(this).removeClass(hover_css);
  });
}

// 判断操作系统
function check_os() {
	var os_type = "MS Windows";
	windows = (navigator.userAgent.indexOf("Windows",0) != -1)?1:0;
	mac = (navigator.userAgent.indexOf("Mac",0) != -1)?1:0;
	linux = (navigator.userAgent.indexOf("Linux",0) != -1)?1:0;
	unix = (navigator.userAgent.indexOf("X11",0) != -1)?1:0;
 
	if (windows) os_type = "MS Windows";
	else if (mac) os_type = "Apple mac";
	else if (linux) os_type = "Lunix";
	else if (unix) os_type = "Unix";
 
	return os_type;
}
